import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: false,
		hasLogin: false,
		userName: "",
		userId: '',
		tenantId: '',
		token: '',
		examIndex: 0,
		practiceIndex: 0,
		sysInfo: {},
		accountList: [],
		questionList: [{}],
		testIndex: 0
	},
	mutations: {
		login(state, userName) {
			state.userName = userName || '新用户';
			state.hasLogin = true;
		},
		logout(state) {
			state.userName = "";
			state.hasLogin = false;
		},
		setQuestionList(state, list) {
			state.questionList = list
		},
		setQuestionListChecked(state, {
			testIndex,
			index,
			Bool
		}) {
			state.questionList[testIndex].questionOptionEntities[index].checked = Bool
		},
		setQuestionListIscollect(state, {
			testIndex,
			isShowToast,
			val
		}) {
			state.questionList[testIndex].collect = val
			if (isShowToast) {
				if (val) {
					uni.showToast({
						title: '收藏成功',
						icon: 'none'
					}, 500)
				} else {
					uni.showToast({
						title: '取消收藏',
						icon: 'none'
					}, 500)
				}
			}
		},
		setQuestionListUserAnsw(state, {
			testIndex,
			answ
		}) {
			state.questionList[testIndex].userAnsw = answ
		},
		setTestIndex(state, testIndex) {
			state.testIndex = testIndex
		}
	}
})

export default store
